<div style='clear:both;'></div>
<div style='float:left;'>
	<h2>And finalists are ... </h2>
</div>
<div style='clear:both;'></div>
<form name='votefrm' id='votefrm' class='funcSubmitVote' action='<?php echo HTTP_SERVER; ?>vote#result' method='post'>
	<?php
		if(isset($nominats) && count($nominats)>0)
			echo "<b>Note: </b><span class='success'>The blog that sent you here has been selected for your vote.</span> You can scroll down and vote for blogs in other categories, or otherwise just <a href='#result'>skip to the bottom</a> to submit your vote. Thank you.</span>";
		
		$count=0;
		$db->Query("SELECT * FROM category;");
		$cats = $db->getResults();
		foreach($cats as $c) {
			if($count%2) { $side = "right"; $otherside = "left"; }
			else { $side = "left"; $otherside = "right"; }
			echo "<div class='".$side." box' style='border-".$otherside.":1px solid #ddd;border-bottom:1px solid #ddd;border-top:1px solid #ddd;'>
							<h2 class='header'>".$c['name']."</h2>
							<div class='contentBody'><p>".$c['description']."</p>";
			$contestants = array();
			$db->Query("SELECT contestant.name, contestant.url, nomination.id, nomination.nomination_count, nomination.vote_count
										FROM category, contestant, nomination
										WHERE category.id = nomination.category_id AND contestant.id = nomination.contestant_id AND category.id = '".$c['id']."' AND vote_count > 0
										ORDER BY nomination.vote_count DESC, nomination.nomination_count DESC LIMIT 0, 11;");
			while($db->getRow()) {
				$contestants[] = array('nomination_id'=>$db->access[2], 
															 'blog_name'=>$db->access[0], 
															 'blog_url'=>$db->access[1], 
															 'nominate_count'=>$db->access[3],
															 'vote_count'=>$db->access[4]);
			}
			/*
			foreach ($contestants as $key => $row) {
				$a_nomination_id[$key] = $row['nomination_id'];
				$a_name[$key] = $row['blog_name'];
				$a_url[$key] = $row['blog_url'];
				$a_nominate_count[$key] = $row['nominate_count'];
				$a_vote_count[$key] = $row['vote_count'];
			}
			array_multisort($a_vote_count, SORT_DESC, $a_nominate_count, SORT_DESC, $contestants);
			*/
			shuffle($contestants);
			$i=0;
			foreach ($contestants as $key => $row) {
				echo "<div class='voter'><br />
								<input type='radio' name='category_".$c['id']."' id='".$row['nomination_id']."' value='".$row['nomination_id']."'"; 
								if(in_array($row['nomination_id'], $nominats)) echo " checked='checked'"; echo " />
								<label for='".$row['nomination_id']."'>
									<a href='http://".$row['blog_url']."' title='view this blog in a new window' target='_blank'>".$row['blog_name']."</a>
								</label>
							</div>";
				$i++;
				if(($c['id']!=4) && $i>=10) break;
			}
			echo "<div style='clear:both;'></div></div>
						</div>";
			$count++;
			unset($contestants);
		}
	?>
	<div class="center box">
		<h2 class="header">Submit your Vote</h2>
		<div class='contentBody'>
			<a href='#' name='result' id='result'></a>
			<div id='results-flash'><?php if($flash!="") echo $flash; ?></div>
			<?php if(!$clearform) { ?>
			<div id='results'>
				<p>Please type your email address and the verification code and you will be sent an email to confirm your vote.</p>
				<label for='email'><b>Your Email Address: </b></label> <span id="inf_email">*</span><br />
				<input type='text' name="email" id="email" class='required validate-email' size="50" value='<?php echo $post_email; ?>' />
				<p class='left'>
					<label for='validate'><b>Security Code: </b></label> <span id="inf_validate">*</span><br />
					<span><img src="<?php echo HTTP_SERVER.INCLUDE_DIR; ?>captcha.php?<?php echo $id; ?>" alt="" /></span>
					<input class='required security-code' type="text" name="validate" id="validate" value="<?php echo $code; ?>" size="5" maxlength="5" />
					<input type='hidden' name="id" value="<?php echo $id; ?>">
				</p>
				<p style='float:left;padding:13px;'>
					<input type='submit' name='submit' id='submit' class='bigbutton left' value='Submit' />
					&nbsp;<span id='vote-loading' class='hideme spinner'> </span>
				</p>
			</div>
			<?php } ?>
		</div>
	</div>
</form>